package demo2;

public class Test1 {
    public static void main(String[] args) {
        String s = "A man, a plan, a canal: Panama";
        String s1 = s.toLowerCase();
        char[] chars = s1.toCharArray();

        if (s.length() == 0) {
            return; //return true
        }

        for (int i = 0, j = chars.length - 1; i <= j; ) {
            if ((isLetter(chars[i]) == 1) && (isLetter(chars[j]) == 1)) {
                if (!(chars[i] == chars[j])) {
                    return;  //return false
                }
                i++;
                j--;
            } else if (isLetter(chars[i]) == -1) {
                i++;
            } else {
                j--;
            }
        }
        return;  //return true


    }
    //判断是不是字母数字  1是   -1不是
    public static int isLetter(char ch) {
        if ((ch >= 'a' && ch <= 'z') ||
            (ch >= '0' && ch <= '9')) {
            return 1;
        }
        return -1;
    }
}
